#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //child
        char* const argv[] = {"./test_2"};
        printf("start: child process pid: %d, ppid: %d\n", getpid(), getppid());
        sleep(2);
        //int i = execl("/usr/bin/ls", "ls", "-a", "-l", NULL); //运行命令
        //execl("./test_2", "test_2", NULL); //运行自己的程序
        // execv("./test_2", argv); //运行自己的程序
        execl("./test.sh", "./test.sh", NULL);
        printf("after: child process pid: %d, ppid: %d\n", getpid(), getppid());
        exit(12);
    }
    else
    {
        sleep(5);
        //father
        pid_t ret  = waitpid(id, NULL, 0);
        if(ret == id)
        {
            printf("this is father process, pid = %d\n", getpid());
        }
    }

    sleep(5);


    return 0;
}
